package com.zhangchuchu.neohealth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhangchuchu.neohealth.entity.Comments;
import com.zhangchuchu.neohealth.entity.DTO.CommentsDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评论表(Comments)表数据库访问层
 *
 * @author makejava
 * @since 2025-03-29 20:34:33
 */
@Mapper
public interface CommentsMapper extends BaseMapper<Comments> {
    @Select("""
        SELECT c.id, c.content, c.created_at, c.likes, c.is_main, c.floor, 
               c.user_id, c.community_id, u.nickname, u.avatar
        FROM comments c
        LEFT JOIN users u ON c.user_id = u.id
        WHERE c.community_id = #{communityId}
        AND c.is_main = 1
        ORDER BY c.floor ASC
    """)
    List<CommentsDTO> getMainCommentsByCommunityId(@Param("communityId") Long communityId);
    @Select("""
        SELECT c.id, c.content, c.created_at, c.likes, c.is_main, c.floor, 
               c.user_id, c.community_id, u.nickname, u.avatar
        FROM comments c
        LEFT JOIN users u ON c.user_id = u.id
        WHERE c.community_id = #{communityId}
        AND c.comment_id = #{commentId}
        AND c.is_main = 0
        ORDER BY c.floor ASC
    """)
    List<CommentsDTO> getSubCommentsByCommunityId(@Param("communityId") Long communityId,@Param("commentId") Long commentId);
    @Select("""
        SELECT c.id, c.content, c.created_at, c.likes, c.is_main, c.floor, 
               c.user_id, c.community_id, u.nickname, u.avatar
        FROM comments c
        LEFT JOIN users u ON c.user_id = u.id
        WHERE c.community_id = #{communityId}
        AND c.comment_id = #{commentId}
        AND c.is_main = 0
        ORDER BY c.floor ASC
        LIMIT 1
    """)
    List<CommentsDTO> getOneSubCommentsByCommunityId(@Param("communityId") Long communityId,@Param("commentId") Long commentId);
}
